$(document).ready(function(){
    $('.icon-plus-sign').on('click',function(){
        var inputValue = Number($('#numberOfInstances').val()) + 1;
        $('#numberOfInstances').val(inputValue);
        if(inputValue>1){
            $('#slaveTypes').show('fast');
        }

    });
    $('.icon-minus-sign').on('click',function(){
        var inputValue = Number($('#numberOfInstances').val()) - 1;
        if(inputValue == 0){
            return false;
        }
        if(inputValue==1){
            $('#slaveTypes').hide('fast');
        }
        $('#numberOfInstances').val(inputValue);
    });

    // Validate data
    $("#modal_error").dialog({
        autoOpen: false,
        draggable: false,
        modal: true,
        resizable: false,
        buttons: {
            Ok: function(){
                $(this).dialog( "close" );
            }
        }
    });

    $("#creationForm").on("submit", function(event){
        var name = $("#jobName").val(),
            bdtools = $("#bdtools").find("input:checked").length;

        var error = "";
        if (name == "") error += "- Please, select a job name <br />";
        if (bdtools == 0) error += "- Please, select at least one big-data tool<br />";

        if (error != ""){
            // Show Modal Error
            $("#modal_error").dialog({
                dialogClass: "validationError"
            });
            $("#modal_error").dialog("open");
            $("#modal_error").find(".msg").html(error);

            return false;
        }
    });
});
